import pandas as pd
import openpyxl # 导入 pandas 库

class ExcelReader:
    def __init__(self, file_path):
        self.file_path = file_path  # 存储文件路径

    def read_excel(self, sheet_name='Sheet1', usecols="A:C", nrows=7):
        try:
            # 读取特定工作表和范围的 Excel 文件
            df = pd.read_excel(self.file_path, sheet_name=sheet_name, usecols=usecols, nrows=nrows, engine='openpyxl')
            print(f"从工作表 {sheet_name} 读取数据成功！")
            print(df)
            return df
        except FileNotFoundError:
            print(f"文件未找到：{self}")
        except Exception as e:
            print(f"读取 Excel 文件时出现错误：{e}")


#with open("example.xlsx", 'r', encoding='gbk') as file:
#    content = file.read()
#    print(content)

if __name__ == '__main__':
    data = ExcelReader("example.xlsx")
    data1 = data.read_excel()
    print(data1)
